﻿using System;

public class TurnManager
{
    // make turn with time
    public void Update(double deltaTime)
    {
        m_totalTick += deltaTime;
        double turnGenerated = (m_totalTick * m_turnFactor) / ONE_SEC;
        if (turnGenerated > 1.0f)
        {
            m_turn += (int)System.Math.Truncate(turnGenerated); // 정수부만 
            m_totalTick -= System.Math.Truncate((turnGenerated) / m_turnFactor); // 쓰고난 것버리기 
        }
    }

    public void SetTurnFactor(double factor)
    {
        m_turnFactor = factor;
    }

    // 턴을 소유하고 있는가?
    public bool HaveTurn()
    {
        return (m_turn > 0);
    }

    public int GetTurn()
    {
        return m_turn;
    }

    public double GetTotalTick()
    {
        return m_totalTick;
    }

    public bool UseTurn(int turn = 1)
    {
        if (m_turn < turn)
        {
            return false;
        }

        m_turn -= turn;
        return true;
    }

    private const double ONE_SEC = 1.0f; 
    private double m_totalTick = 0.0f;
    private int m_turn = 0;
    private double m_turnFactor = 1.0f;
}

